<template>
  <div>
    <can-edit-table
      refs="table"
      v-model="dataList"
      @on-delete="handleDel"
      @on-edit2="handleEdit"
      @on-view="handleView"
      :columns-list="columnList">
    </can-edit-table>
    <Page style="float: right; margin:10px;" :current="current_num" :total="page_count" :pageSize="page_size" showElevator showSizer @on-page-size-change="handleSizeChange" @on-change="handleChangePage"></Page>

    <Modal v-model="modal_edit_show" title="编辑简历进展" width="400" :mask-closable="false">

      <div style="text-align:center;">
        <Form ref="recruitFormValidate" :model="resumeFormValidateEdit" :label-width="70">

          <Form-item label="姓名">
            <span>{{resumeFormValidateEdit.name}}</span>
          </Form-item>

          <Form-item prop="process_state" label="招聘进展">
            <Select v-model="resumeFormValidateEdit.process_state" placeholder="请选择招聘进展">
              <Option value="简历筛选中">简历筛选中</Option>
              <Option value="笔试中">笔试中</Option>
              <Option value="面试中">面试中</Option>
              <Option value="offer">offer</Option>
              <Option value="入职">入职</Option>
            </Select>
          </Form-item>

          <Form-item prop="remark" label="备注">
            <Input v-model="resumeFormValidateEdit.remark" type="textarea" placeholder="请输入备注"/>
          </Form-item>
        </Form>

      </div>

      <div slot="footer">
        <Button type="primary" size="large" long @click="submitEdit">提交</Button>
      </div>
    </Modal>
  </div>
</template>
<script>
  import canEditTable from './part/canEditTable.vue';
  import resumePoolApi from '../api/axios/resumePoolApi'

  export default {
    components: {
      canEditTable
    },
    data () {
      return {
        modal_edit_show: false,
        current_num: 1,
        page_count: 5,
        page_size: 5,
        current_index: 1,
        resumeFormValidateEdit:{
          jobRecordId: '',
          userId: '',
          name: '',
          process_state: '',
          remark: ''
        },
        columnList: [
          {
            title: '序号',
            type: 'index',
            align: 'center'
          },
          {
            title: '姓名',
            key: 'name',
            align: 'center',
            sortable: true
          },
          {
            title: '性别',
            key: 'sex',
            align: 'center',
            sortable: true
          },
          {
            title: '岗位',
            key: 'job',
            align: 'center',
            sortable: true
          },
          {
            title: '学历',
            key: 'degree',
            align: 'center',
            sortable: true
          },
          {
            title: '学校',
            key: 'school',
            align: 'center',
            sortable: true
          },
          {
            title: '内推',
            key: 'is_recommend',
            align: 'center',
            sortable: true
          },
          {
            title: '进度',
            key: 'process_state',
            align: 'center',
            sortable: true,
            editable: true
          },
          {
            title: '备注',
            key: 'remark',
            align: 'center',
            sortable: true,
            editable: true
          },
          {
            title: '操作',
            align: 'center',
            width: 168,
            key: 'handle',
            handle: ['view', 'edit2', 'delete']
          }
        ],
        dataList: []
      }
    },
    methods: {
      handleDel (val, index) {

        let that = this;
        resumePoolApi.deleteResumeRecord({
          jobRecordId: val[index].jobRecordId
        },{
          success (res) {
            if (res.data.status === 200) {
              that.$Message.success("删除成功");

              that.dataList.splice(index,1);

            }else {
              that.$Message.error("删除失败");
              console.log("deleteResumeRecord请求失败：" + res.data);
            }
          }
        });

//        console.log(JSON.stringify(val));
//        this.$Message.success('删除了第' + (index + 1) + '行数据');
      },
      handleEdit (val, index) {
        this.resumeFormValidateEdit = val[index];
        this.current_index = index;
        this.modal_edit_show = true;
//        console.log(JSON.stringify(val));
//        this.$Message.success('修改了第' + (index + 1) + '行数据');
      },
      handleView (val, index) {
        this.$router.push({ path: `/resume_pool/view_resume/${val[index].userId}` })
//        console.log(JSON.stringify(val));
//        this.$Message.success('查看了第' + (index + 1) + '行数据');
      },
      submitEdit (){

        let that = this;
        resumePoolApi.updateResumeRecord({
          jobRecordId: that.resumeFormValidateEdit.jobRecordId,
          resumeId: that.resumeFormValidateEdit.resumeId,
          userId: that.resumeFormValidateEdit.userId,
          process_state: that.resumeFormValidateEdit.process_state,
          remark: that.resumeFormValidateEdit.remark
        },{
          success (res) {
            if (res.data.status === 200) {
              that.$Message.success("修改成功");

              let arr = JSON.parse(JSON.stringify(that.dataList));
              arr[that.current_index].process_state = that.resumeFormValidateEdit.process_state;
              arr[that.current_index].remark = that.resumeFormValidateEdit.remark;
              that.dataList = arr;

            }else {
              that.$Message.error("修改失败");
              console.log("updateResumeRecord 请求失败：" + res.data);
            }
          }
        });

        that.modal_edit_show = false;

      },
      handleChangePage(pageNum){
        this.current_num = pageNum;
        this.updatePageList();
      },
      handleSizeChange(pageSize){
        this.page_size = pageSize;
        this.updatePageList();
      },
      updatePageList(){
        let that = this;
        resumePoolApi.getResumeListByType({
          recruitType: '校招'
        },{
          currentPage: that.current_num,
          pageSize: that.page_size
        },{
          success (res) {
            if (res.data.status === 200) {
              that.dataList = res.data.data.list;
              that.page_count = res.data.data.count;
            }else {
              console.log("getResumeListByType请求失败：" + res.data);
            }
          }
        })
      }
    },
    created() {
      this.updatePageList();
    }
  }
</script>
<style>

</style>
